<?php

namespace app\models;

use Yii;
use yii\db\ActiveRecord;

class NormalUser extends ActiveRecord
{

    public $password1, $password2;

    public static function tableName()
    {
        return 'NormalUser';
    }

    public function scenarios()
    {
        $scenarios = parent::scenarios();
        $scenarios['login'] = ['email', 'password', 'verifyCode'];
        $scenarios['forget'] = ['email', 'password', 'verifyCode', 'password2'];
        $scenarios['register'] = ['email', 'password', 'verifyCode', 'password2'];
        $scenarios['modify'] = ['realname', 'sex', 'published','telephone', 'age', 'school', 'degree', 'major', 'address', 'expect', 'experience', 'information','skill_1','head_img'];
        $scenarios['resetPassword'] = ['password1', 'password2'];
        return $scenarios;
    }

    public function rules()
    {
        return [
            [['email', 'password', 'password2', 'verifyCode'], 'required', 'message' => '内容不能为空', 'on' => ['login', 'forget', 'register']],
            ['email', 'email', 'message' => '邮箱格式不正确', 'on' => ['login', 'forget', 'register']],
            [['realname', 'sex', 'published', 'telephone', 'age', 'school', 'degree', 'major', 'address', 'expect', 'experience', 'information'], 'required', 'message' => '内容不能为空', 'on' => 'modify'],
            ['head_img','file','skipOnEmpty'=>true,'extensions'=>'png,jpg,jpeg','message'=>'请确保你的图片是有效的'],
            ['password2', 'compare', 'compareAttribute' => 'password', 'message' => '两次输入密码不一致', 'on' => ['forget', 'register']],
            ['password1', 'compare', 'compareAttribute' => 'password2', 'message' => '两次输入密码不一致', 'on' => ['resetPassword']],
            [['password1', 'password2'], 'required', 'message' => '内容不能为空', 'on' => 'resetPassword'],
            ['verifyCode', 'captcha', 'message' => '验证码输入错误', 'captchaAction' => '/admin/login/captcha', 'on' => ['login', 'forget', 'register']],
        ];
    }

}